﻿<cfscript>
/** 
* Senate Frameworks workloadFactory
* 
* @hint "The WorkLoad Calculator." 
*/ 

component 
	displayname="public.service.handler.workloadFactory" 
	output=false 
	{

	/* PROPERTIES */
	
	/**
	* @hint "初始化对象"
	*/
	public public.service.handler.workloadFactory function init() output=false {
		return this;
	}

	
	/**
	* @hint "返回数学公式"
	* 
	* @templateId "公式模版"
	* @argString "公式参数"
	*/
	public string function getLatex( required string templateId, required string argString ) output=false {
		
		/* 生成公式模版 */
		var latex = getLatexTemplate( arguments.templateId );
			
		/* 生成参数替换关系 */
		var argsPares = "";
		
		if ( arguments.argString neq "NOP" ) {
			argsPares = arguments.argString;
		}

		for ( var pare in listToArray( argsPares, "," ) ) {
			latex = replace( latex, listFirst(pare, "="), listLast(pare, "="), "one" );
		}
			
		return latex;
	}
	
	
	/**
	* @hint "返回数学公式中参数及说明"
	* 
	* @templateId "公式模版"
	*/
	public array function getLatexTemplateArgs( required string templateId ) output=false {
		
		var argsArray = [];

		/* 
			参数实体
			[ 'LaTex', 'Description', 'T/F' ]
		*/
		
		switch ( arguments.templateId ) {
			
			case "L1":
				/* 理论课计算公式模版 */
				
				arrayAppend( argsArray, [ "W_e", "双语教学系数", "T" ] );
				arrayAppend( argsArray, [ "C_t", "课程理论学时", "T" ] );
				arrayAppend( argsArray, [ "P", "实际上课人数", "T" ] );

				arrayAppend( argsArray, [ "W_1", "调节系数一", "F" ] );
				arrayAppend( argsArray, [ "W_2", "调节系数二", "F" ] );
				arrayAppend( argsArray, [ "P_s", "最低计算人数", "F" ] );
				arrayAppend( argsArray, [ "P_0", "标准班人数", "F" ] );

				break;
				
			case "S1":
				/* 实践课计算公式模版 */
				
				arrayAppend( argsArray, [ "W_0", "调节系数", "F" ] );
				arrayAppend( argsArray, [ "P", "实际上课人数", "T" ] );

				break;
			
			case "S2":
				/* 实践课计算公式模版 */
				
				arrayAppend( argsArray, [ "C_p", "课程实践学时", "T" ] );
				arrayAppend( argsArray, [ "P", "实际上课人数", "T" ] );

				arrayAppend( argsArray, [ "W_0", "调节系数", "F" ] );
				arrayAppend( argsArray, [ "C_0", "标准学时", "F" ] );
				
				break;
			
			case "S3":
				/* 实践课计算公式模版 */
				
				arrayAppend( argsArray, [ "W_e", "双语教学系数", "T" ] );
				arrayAppend( argsArray, [ "W_p", "实践加权系数", "T" ] );
				arrayAppend( argsArray, [ "C_p", "课程实践学时", "T" ] );

				arrayAppend( argsArray, [ "W_0", "调节系数", "F" ] );
				arrayAppend( argsArray, [ "C_0", "标准学时", "F" ] );
				
				break;
			
			case "S4":
				/* 实践课计算公式模版 */
				
				arrayAppend( argsArray, [ "W_e", "双语教学系数", "T" ] );
				arrayAppend( argsArray, [ "W_p", "实践加权系数", "T" ] );
				arrayAppend( argsArray, [ "C_p", "课程实践学时", "T" ] );
				arrayAppend( argsArray, [ "P", "实际上课人数", "T" ] );
				
				arrayAppend( argsArray, [ "W_1", "调节系数一", "F" ] );
				arrayAppend( argsArray, [ "W_2", "调节系数二", "F" ] );
				arrayAppend( argsArray, [ "P_0", "标准班人数", "F" ] );
				
				break;
			
			case "S5":
				/* 体育课计算公式模版 */
				
				arrayAppend( argsArray, [ "P", "实际上课人数", "T" ] );

				break;
			
		}
		
		return argsArray;
	}
	
	
	/**
	* @hint "返回数学公式模版"
	* 
	* @templateId "公式模版"
	*/
	public string function getLatexTemplate( required string templateId ) output=false {
		
		switch ( arguments.templateId ) {
			
			case "L1":
				/* 理论课计算公式模版 */
				return "eql=W_eC_t\left({W_1}\frac{\max(P,P_s)}{{P_0}}+{W_2}\right)";
				break;

			case "S1":
				/* 实践课计算公式模版 */
				return "eql=W_0P";
				break;

			case "S2":
				/* 实践课计算公式模版 */
				return "eql=W_0\frac{C_p}{C_0}P";
				break;

			case "S3":
				/* 实践课计算公式模版 */
				return "eql=W_eW_pW_0\frac{C_p}{C_0}P";
				break;

			case "S4":
				/* 实践课计算公式模版 */
				return "eql=W_eW_pC_p\left(W_1\frac{P}{P_0}+W2\right)";
				break;

			case "S5":
				/* 体育课计算公式模版 */
				return "eql=P";
				break;
			
		}
		
		return "NOP";
	}

}

</cfscript>